package Servlet;

import Until.BaseDao;
import Until.BaseModel;
import com.alibaba.fastjson.JSON;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

@WebServlet(name = "SelectUserByIdServlet",urlPatterns = "/selectuserbyid")
public class SelectUserByIdServlet extends HttpServlet {
    BaseDao baseDao = new BaseDao();

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        this.doPost(req, resp);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String id=req.getParameter("id");
        String sql="select * from t_user where id="+id;
        List list=baseDao.query(sql,null);
        BaseModel baseModel = new BaseModel();
        baseModel.setCode(0);
        baseModel.setMessage("用户信息查询成功！");
        baseModel.setData(list);
        String baseModelStr=JSON.toJSONString(baseModel);
        resp.getWriter().write(baseModelStr);
        resp.getWriter().flush();
        resp.getWriter().close();
    }
}
